package Product;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

//com k
public class Category implements Serializable{
	private static int id_next = 0;
	private int id;
	private List <Category> subCategories = new ArrayList<Category>() ;
	private String name;

	Category(String aName){
		name = aName;
		id = ++id_next;
	}

	@Override
	public String toString(){
		return "Kategoria: "+name+" id: "+id;	
	}

	public void addSubCategory(Category c){
		subCategories.add(c);
	}

	public String showAllCategories(){
		String r=name+":\n";

		for(Category c: subCategories){
			r =r+"\t"+c+" \n";
			
			if(!c.subCategories.isEmpty()) r=r+c.showAllCategories(1);
		}	

		return r;		
	}
	
	public String showAllCategories(int indent){
		String r="";
		
		String tab="";
		for (int i = 0; i < indent; i++) {
			tab+="\t";
		}
		
		for(Category c: subCategories){
			r =r+tab+c+"\n";
			
			if(!c.subCategories.isEmpty()) r=r+c.showAllCategories(indent+1);
		}	

		return r;		
	}
	
	

	
	//for test purposes
	public static void main(String[] args) {
		//main
		Category a = new Category("glosniki");
		Category b = new Category("wzmacniacze");
		Category c = new Category("radia");
		
		//sub a level 1
		Category e = new Category("basowe");
		Category f = new Category("�redniotonowe");
		
		a.addSubCategory(e);
		a.addSubCategory(f);
		
		//sub glosniki/basowe/ - level-2
		Category g = new Category("10\"");
		Category h = new Category("12\"");
			
			Category x = new Category("sub - 12");
			h.addSubCategory(x);
				Category y = new Category("sub-sub-12");
				x.addSubCategory(y);
		Category i = new Category("15\"");
		
		e.addSubCategory(g);
		e.addSubCategory(h);
		e.addSubCategory(i);
		
		//wzmacniacze sub level 1
		Category o = new Category("1-kana�owe");
		Category p = new Category("2-kana�owe");
		Category r = new Category("4-kana�owe");
				
		
		b.addSubCategory(o);
		b.addSubCategory(p);
		b.addSubCategory(r);
		
		
		List<Category> category = new ArrayList<Category>();
		category.add(a);
		category.add(b);
		category.add(c);
		

		for(Category d: category){
			System.out.println(d.showAllCategories());
		}
		

	}


}//end class Category
